﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;
namespace SZ.Mech
{
    public class DamageWorker_AddHediff : DamageWorker
    {
        public override DamageResult Apply(DamageInfo dinfo, Thing thing)
        {
            if (thing is Pawn pawn)
            {
                Hediff hediff = HediffMaker.MakeHediff(dinfo.Def.hediff, pawn);
                hediff.Severity = dinfo.Amount;
                pawn.health.AddHediff(hediff, null, dinfo);

                ExtraDamageExtension extraDamageExtension = dinfo.Def.GetModExtension<ExtraDamageExtension>();

                foreach (ExtraDamage extraDamage in extraDamageExtension.extraDamages)
                {
                    if (Rand.Chance(extraDamage.chance))
                    {
                        DamageInfo dinfo2 = new DamageInfo(extraDamage.def, extraDamage.amount, extraDamage.AdjustedArmorPenetration(), dinfo.Angle, dinfo.Instigator, null);
                        pawn.TakeDamage(dinfo2);
                    }
                }

            }
            return base.Apply(dinfo, thing);
        }
        
    }
    
}

